<template>
  <div class="mod-menu main-container">
    <!-- 操作栏 -->
    <div class="operation-bar">
      <div
        v-if="isAuth('sys:menu:save')"
        class="default-btn primary-btn"
        @click="airportStationAddOrUpdateHandle()"
      >
        {{ $t("sysManagement.add") }}
      </div>
    </div>

    <!-- 表格 -->
    <div class="table-con sys-menu-table">
      <el-table
        :data="dataList"
        header-cell-class-name="table-header"
        style="width: 100%"
        row-key="id"
      >
        <el-table-column
          prop="name"
          treeKey="id"
          width="260"
          :label="$t('publics.name')"
        >
        </el-table-column>
        <el-table-column prop="orderNum" align="center" :label="$t('sys.orderNum')">
          <template slot-scope="scope">
            {{ scope.row.orderNum }}
          </template>
        </el-table-column>
        <el-table-column prop="disabled" align="center" :label="$t('sys.disabled')">
          <template slot-scope="scope">
            <span v-if="scope.row.disabled">{{ $t("sys.yes") }}</span>
            <span v-else>{{ $t("sys.no") }}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="floorNum" align="center" :label="$t('sys.floorNum')">
        </el-table-column> -->
        <!-- <el-table-column prop="securityCheckArea" align="center" :label="$t('sys.securityCheckArea')">
          <template slot-scope="scope">
            <span v-if="scope.row.securityCheckArea">{{ $t("sys.yes") }}</span>
            <span v-else>{{ $t("sys.no") }}</span>
          </template>
        </el-table-column> -->
        <el-table-column
          fixed="right"
          align="center"
          width="150"
          :label="$t('sys.operation')"
        >
          <template slot-scope="scope">
            <div class="text-btn-con">
              <div
                v-if="isAuth('sys:menu:update')"
                class="default-btn text-btn"
                @click="airportStationAddOrUpdateHandle(scope.row.id)"
              >
                {{ $t("sysManagement.modify") }}
              </div>
              <div
                v-if="isAuth('sys:menu:delete')"
                class="default-btn text-btn"
                @click="deleteHandle(scope.row)"
              >
                {{ $t("coupon.delete") }}
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 弹窗, 新增 / 修改 -->
    <AirportStationAddOrUpdate
      v-if="airportStationAddOrUpdateVisible"
      ref="AirportStationAddOrUpdate"
      @refreshDataList="getDataList"
    />
  </div>
</template>

<script>
import AirportStationAddOrUpdate from "./airport-station-add-or-update.vue";
import { treeDataTranslate } from "@/utils";
export default {
  data() {
    return {
      dataList: [],
      dataListLoading: false,
      airportStationAddOrUpdateVisible: false,
    };
  },
  components: {
    AirportStationAddOrUpdate,
  },
  created() {
    this.getDataList();
  },
  methods: {
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/admin/platform/airportStation/list"),
        method: "get",
        params: this.$http.adornParams(),
      }).then(({ data }) => {
        this.dataList = data;
        this.dataListLoading = false;
      });
    },
    // 新增 / 修改
    airportStationAddOrUpdateHandle(id) {
      this.airportStationAddOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.AirportStationAddOrUpdate.init(id);
      });
    },
    // 删除
    deleteHandle(row) {
      this.$confirm(
        this.$i18n.t("seckill.isDeleOper"),
        this.$i18n.t("text.tips"),
        {
          confirmButtonText: this.$i18n.t("coupon.confirm"),
          cancelButtonText: this.$i18n.t("coupon.cancel"),
          type: "warning",
        }
      ).then(() => {
        this.$http({
          url: this.$http.adornUrl(`/admin/platform/airportStation/delete/${row.id}`),
          method: "delete",
          data: this.$http.adornData(),
        }).then(({ data }) => {
          if (row.type === 1) {
            this.$router.go(0);
          }
          this.$message({
            message: this.$i18n.t("publics.operation"),
            type: "success",
            duration: 1500,
            onClose: () => {
              this.getDataList();
            },
          });
        });
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.mod-menu.main-container {
  padding-top: 0;
}
</style>
